import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { SignService } from './../../../core/service/sign.service';
import { UserInfoService } from './../../../core/service/user-info.service';
import { RegionNumber } from 'src/app/model';
import { I18nService } from 'src/app/core/i18n/i18n.service';
import { MemberService } from '../../member-center/member.server';
import { StorageService } from 'src/app/core/sotrage/storage.service';
import { concatMap } from 'rxjs/operators';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss'],
  providers: [
    SignService
  ]
})
export class LoginComponent implements OnInit {

  index = 0;

  loginForm: FormGroup;

  regionNumbers: RegionNumber[] = [];

  
  ngOnInit() {
    this.initEmailForm()
  };
  
  submit() {
    this.toLogin('登陆',this.loginForm.value);
  };
  
  toPage(url: string) {
    this.router.navigateByUrl(url);
  };
  

  private initEmailForm() {
    this.loginForm = this.fb.group({
      loginId: [null, [Validators.required]],
      loginPwd: [null, []],
    });
  };
  
  async toLogin(url, data) {
    // let tag = await this.memberServer.getAJX(url,data);
    // this.memberServer.getApiSuccess(tag,false) ? this.successListOk(tag.data, url) : '';
    this.successListOk(data)
  };
  
  public successListOk(data):void{
    this.userInfoService.saveUserInfo(data);
    switch (data.loginId) {
        case 'suzhen':
            this.router.navigate(["/member/center/setdzcf"]);
            break;
        case 'shibaoyu':
            this.router.navigate(["/member/center/yaoshihome"]);
            break;
        default:
                this.message.error('用户名错误', { nzDuration: 1500 })
            break;
    };
  };
  constructor(
    private fb: FormBuilder,
    private router: Router,
    private memberServer: MemberService,
    private message: NzMessageService,
    private userInfoService: UserInfoService
  ) { }
};
